Package xunome

Source Code of xunome.xUnoME

package xunome;

/**
*
* @author Sem iNick
* Main class for the game
*/

import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.StringItem;
import xunome.graphics.Menu;
import xunome.game.BaseGame;
import xunome.game.SinglePlayer;

public class xUnoME extends MIDlet implements CommandListener {

    private Display lcd;
    private BaseGame game = null;
   
    /**
     * Default midlet constructor
     */
    public xUnoME() {

        lcd = Display.getDisplay(this);
        setMain();
    }

    /**
     * It's necessary to implement this function to start midlet
     */
    public void startApp() {

        /*if (game != null) {

            game.startGame();
        }*/
    }


    public void destroyApp(boolean unco) {

        if (game != null) {

            game.stopPlaying();
        }
        game = null;
        lcd = null;
    }

    public void pauseApp() {

        /*if (game != null) {
           
            game.pauseGame();
        }*/
    }

    public Display getLCD() {
        return lcd;
    }

    public void setMain() {

        game = null;
        Menu main = new Menu(Menu.MAIN, this);
        lcd.setCurrent(main);
        main.startListening();
    }

    public void setHelp() {
       
        Form help = new Form("xUno ME - Help");
        StringItem helpText = new StringItem("xUNO ME",
                "This game is based on original UNO made by Mattel so it's not a"
                + " copy of UNO.\nThe game aim is to discard all cards first. "
                + "Each player starts with 7 cards and a random card from the "
                + "deck is put on the table. In your turn, the player just can "
                + "discard a card if it has some card with same color, same number, "
                + "or same type of table card or wild draw four, and wild. "
                + "When the player has one card, the player is compulsory to \"call xUno\""
                + "or it will be penalized with 3 cards.\n\n");
        help.append(helpText);

        StringItem commands = new StringItem("Keyboard Commands:",
                "Left or 4: Move the selection to left.\n" +
                "Right or 6: Move the selection to right.\n" +
                "Fire or 5: Discard the selected card if possible.\n" +
                "0: Calls xUno when the player has 1 card.\n" +
                "5: Get a card from de deck if the player doesn't have a possible move.\n" +
                "1,3,7,9: Choose, respectively, the colors blue, green, red and yellow.\n" +
                "*: Back to main menu."
                );
        help.append(commands);

        StringItem aboutTouchCommands = new StringItem("Touchscreen Commands:",
                "Click in card to try discard it.\n"
                + "Click in deck to get one card.\n"
                + "Click in middle of discarded cards to call xUno.\n"
                + "Click in colored square to choose color."
                );
        help.append(aboutTouchCommands);

        help.addCommand(new Command("Back", Command.BACK, 0));
        help.setCommandListener(this);
        lcd.setCurrent(help);
    }

    public void commandAction(Command c, Displayable d) {

        if(c.getCommandType() == Command.BACK) {

            setMain();
        }
    }

    public void createSinglePlayerGame(int nPlayers) {

        game = new SinglePlayer(nPlayers, this);
        lcd.setCurrent(game.getCanvas());
        game.getCanvas().refresh();
        game.startGame();
   }
}
TOP

Related Classes of xunome.xUnoME

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.